//生成上校藏身地
//指挥部（服务器调用）
//现在上校改为开局就刷，在一直运动中
private ["_marker", "_pos", "_unit2", "_group"];

if(isNil "as_end_pos") then
{
	private _time = time + 10;
	private _disCheck = 25;
	private _dis = 1000;
	private _pos_mk = [as_map_x + random as_map_w, as_map_y + random as_map_h];
	while{!([_pos_mk, _disCheck] call fn_checkPos) || {[_pos_mk, _dis * as_near_scale, "mk_"] call fn_checkNearMarker}}do
	{
		_pos_mk = [as_map_x + random as_map_w, as_map_y + random as_map_h];
		if(time > _time) then{
			if(_dis < 300) then{
				_disCheck = _disCheck - 5;
			}else{
				_dis = _dis * 0.75;
			};
			_time = time + 10;
		};
	};
	
	_marker = createMarker ["mk_end", [_pos_mk, 1000, 1000] call fn_getPosNearLand];
	//_pos_mk getPos [1250 + random 1250, random 360]];
		
	//简单起见，直接显示标记
	/*
	_marker setMarkerShapeLocal "ICON";
	_marker setMarkerTypeLocal "loc_chapel";		
	_marker setMarkerColorLocal "ColorGreen";
	_marker setMarkerDirLocal 0;
	_marker setMarkerText "Garvas";	
	*/
	
	_marker setMarkerShapeLocal "ELLIPSE";
	_marker setMarkerBrushLocal "Border";
	_marker setMarkerSizeLocal [2000, 2000];		
	_marker setMarkerColor "ColorRed";
	//_marker setMarkerAlpha 0.2;
	
	as_show_pos = getMarkerPos _marker;
	as_end_pos =  [_pos_mk select 0, _pos_mk select 1, 0];
	//show_pos用于坐标查看 ，客户端是不知道as_end_pos的
	publicVariable "as_show_pos";
	
	_pos = as_end_pos;
	
	//播放进行曲
	//"Intro" remoteExec ["playMusic"];
	
	//中心防卫点
	//_pos call E99_dasha;
	_pos call (selectRandom as_all_e99);

	//等待中心点创建好
	waitUntil{Sleep 1;!isNil "as_end_created"};
	
	//创建组，如果先创建并没有单位，就会被清理掉，从而导致上校死亡！
	_group = createGroup resistance;//civilian;
	//启用动态模拟
	_group setVariable["no_cleanup", true];
	_group enableDynamicSimulation true;
	//_group spawn fn_squadAI;//先加入，避免上校执行FFIS脚本

	//private _pos_h = [_pos select 0, _pos select 1, 0];//getTerrainHeightASL _pos];
	//上校
	_unit2 = _group createUnit ["I_Story_Officer_01_F", _pos, [], 2, "NONE"];
	_unit2 allowDamage false;
	_unit2 addEventHandler["HandleDamage", {0}];
	
	[_unit2, _pos] spawn fn_runNpc;
	
	//添加军火库
	/*
	
	private _veh_box = createVehicle ["Land_PCSet_01_case_F", _pos getPos [1, random 360], [], 0, "NONE"];
	_veh_box allowDamage false;	
	//_veh_box setVehiclePosition [_pos_h vectorAdd [0,0,1.0], [], 0, "NONE"];
	_veh_box setVariable["no_cleanup", true];

	[ "AmmoboxInit", [ _veh_box, true, {(_this distance _target) < 5} ] ] call BIS_fnc_arsenal;
	*/
	
	//宪兵司令
	["B_GEN_Commander_F", _pos, 5, _group] call fn_createUnit;
	//宪兵
	for "_i" from 1 to 12 do
	{
		["B_GEN_Soldier_F", _pos, 5, _group] call fn_createUnit;
	};
	
	
	//-------------------------------------other group-----------------------
	_group = createGroup resistance;
	//启用动态模拟
	_group setVariable["no_cleanup", true];
	_group enableDynamicSimulation true;
	_group spawn fn_squadAI;
	//额外增强
	//_____________________________创建守卫_____________________________
	
	_group = [_pos, 2.0, 6, 50, 3] call fn_createGroup;
	_group setVariable["no_cleanup", true];
	_group enableDynamicSimulation true;
	_group = [_pos, 2.0, 6, 50, 3] call fn_createGroup;
	_group setVariable["no_cleanup", true];
	_group enableDynamicSimulation true;
	
	
	sleep 1;
	//防卫点
	if(Param_CarvasDefend > 0) then
	{
		(_pos getPos[100, 0]) call (selectRandom as_all_e100);
	};
	//防卫点
	if(Param_CarvasDefend > 1) then
	{
		(_pos getPos[100, 180]) call (selectRandom as_all_e100);
	};
	//防卫点
	if(Param_CarvasDefend > 2) then
	{
		(_pos getPos[100, 90]) call (selectRandom as_all_e100);
	};
	//防卫点
	if(Param_CarvasDefend > 3) then
	{
		(_pos getPos[100, 270]) call (selectRandom as_all_e100);
	};
	
};



				
			

